#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3+10;
int G[maxn][maxn], d[maxn][maxn], R;

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    cin >> R;
    for (int i = 1; i <= R; ++i) {
        for (int j = 1; j <= i; ++j) {
            cin >> G[i][j];
        }
    }

    for (int r = R; r >=1 ; --r) {
        for (int c = 1; c <= r ; ++c) {
            d[r][c] = G[r][c];
            if(r!=R) d[r][c] += max(d[r+1][c], d[r+1][c+1]);
        }
    }
    cout << d[1][1];
    return 0;
}